import axios from "./config";

// 定义请求接口
/**
 * 
 * @param {String} username 用户
 * @param {String} password 用户密码
 * @param {object} query 切换登入类型
 */
export const loginApi = (username,password,query={},code)=>axios({
    url:"/users/login",
    method:'post',
    params:query,
    data:{
        username,
        password,
        code
    }
})
    


// 获取验证码
export const getCaptchaApi = ()=>axios.get("/users/getCaptcha");

// 校验验证码
export const verifyCaptcha =(captcha="")=>axios.get("/users/verifyCaptcha",{
    params:{
        captcha
    }
})

// 获取登录日志
/**
 * 
 * @param {String} page 第几页
 * @param {String} count 每页的数量
 * @returns {Promise}  返回一个promise
 */
export const getLoginLogApi = (page=1,count=15) =>axios.get("/getloginlog",{
    params:{
        page,
        count
    }
})

// 获取二维码url
export const getQrcodeUrlApi = (sid)=>axios.get("/users/getQrcode",{
    params:{
        sid
    }

})

// 微信登入
export const wechatLoginApi = (wechatCode) =>axios.get("/users/wechatLogin",{
    params:{
        wechatCode
    }
})

// 获取手机验证码
export const getSmsCode = phoneNumber =>axios.post("/sms/send",{
    phoneNumber
})

// 修改用户信息
export const updateUser = (data)=>axios.post("/users/updateUser",data)

//获取权限路由
export const getMenulistApi = ()=>axios.get("/permission/getMenuList")

// 获取学员列表
/**
 * @param {Number} page 页码
 * @param {Number} count 每页的数量
 * @param {String} classes 班级
 * @returns {Promise}  返回一个promise类型的方法
 */
export const getStuListApi = (page=1,count=10,classes="")=>axios.get("/students/getstulist",{
    params:{
        page,
        count,
        class:classes
    }
})

// 增加学员信息
export const addStuApi = data =>axios.post("/students/addstu",data)

// 编辑学员信息
export const updateStuApi = data =>axios.post("/students/updatestu",data)

// 删除学员信息
export const delStuApi = sId =>axios.get("/students/delstu",{
    params:{
        sId
    }
})

// 获取班级列表
export const getClassesApi = ()=>axios.get("/students/getclasses")

// 搜索学员
export const searchStuApi =(page,key,count)=>{
    // 短路运算
    page = page || 1;
    count = count || 10;
    key = key || "";
    return axios.get("/students/searchstu", {
        params:{
            page,
            count,
            key
        }
        
    })
}

// 获取订单
export const getOrderApi = (order_id)=>axios.post("/order/get_order")

// 获取产品
/**
 * 
 * @param {String} category_id 商品所在类目的id
 * @returns 
 */
export const getVipListApi = category_id =>axios.get("/product/get_product",{
    params:{
        category_id
    }
})

// 生成预支付订单
export const preOrderApi = (product_id,quantity=1) =>axios.post("/order/pre_order",{
    product_id,
    quantity
})

// 获取订单详情
export const getOrderDetailApi = (order_id) =>axios.post("/order/get_order",{
    order_id
})

// 发起支付
export const getPayUrlApi = (order_id)=>axios.post("/pay/payment",{
    order_id
})

// 查询支付结果 这个使用ajax轮询的方式查询状态
export const queryPayResultApi = (order_id) =>axios.get("/order/query_order_status",{
    params:{
        order_id
    }
})

//获取所有的用户

export const getAllUsersApi = () => axios.get("/users/getAllUsers");

//添加用户

export const addUserApi = (username, password, nickname) =>
  axios.post("/users/addUser", {
    username,
    password,
    nickname,
  });